﻿using UnityEditor;
using UnityEngine;
using System.Collections;

[CustomEditor(typeof(PUEXGravityAffector))]
public class PUEXGravityAffectorEditor : Editor {

	public void OnSceneGUI ()
	{
		var affector = target as PUEXGravityAffector;
		if (!affector.enabled)
			return;

		Matrix4x4 defaultMatrix = Handles.matrix;
		if (affector.inWorldSpace) {
			Handles.matrix = Matrix4x4.identity;
		} else {
			Handles.matrix = affector.transform.parent.transform.localToWorldMatrix;
		}

		Vector3 value = Handles.PositionHandle (affector.gravityCenter, Quaternion.identity);
		if (GUI.changed) {
			Undo.RecordObject(affector, "PUEXGravityAffector Modify");
			affector.gravityCenter = value;
			EditorUtility.SetDirty(affector);
		}

		Handles.matrix = defaultMatrix;
	}

}
